home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / st80_pr4.lha / st80_pre4 / Foible / foible / Icon-Tools-PPfix.st < prev    next >
Text File  |  1993-07-24  |  5KB  |  182 lines

  1. 'From Objectworks for Smalltalk-80(tm), Version 2.5 of 29 July 1989 on 16 April 1990 at 11:44:52 am'!
  2.  
  3. !IconManager class methodsFor: 'view creation'!
  4.  
  5. openOnDir: aDir
  6.     " open an icon browser on the directory named aDir"
  7.     "IconManager openOnDir: FlowKitDirectory iconDirectory."
  8.  
  9.     | topView listView formView iconDictionary | 
  10.     (Filename named: aDir) exists 
  11.         ifFalse: [PopUpNotifier message:  'Error: directory does not exist'.
  12.                   ^nil].    
  13.     iconDictionary _ self new initDict: aDir.
  14.  
  15.     topView_StandardSystemView
  16.         model: iconDictionary
  17.         label: 'directory:',aDir
  18.         minimumSize: 50@50.
  19.     topView borderWidth: 1.
  20.  
  21.     listView_SelectionInListView
  22.         on:iconDictionary
  23.         aspect: #icon
  24.         change: #icon:
  25.         list: #iconList
  26.         menu: #iconMenu
  27.         initialSelection: #currentIcon.
  28.  
  29.     formView_IconEditorView
  30.         on: iconDictionary
  31.         aspect: #form
  32.         menu: #iconMenu.
  33.  
  34.     topView addSubView: listView
  35.         in: (0@0 extent: 1@0.6)
  36.         borderWidth: 1.
  37.     topView addSubView: formView
  38.         in: (0@0.6 extent: 1@0.4)
  39.         borderWidth: 1.
  40.  
  41.     topView controller open! !
  42.  
  43. !IconManager class methodsFor: 'retrieving forms'!
  44.  
  45. getIcon: iconName fromDirectory: dirName 
  46.     "retrieve an icon from disk "
  47.  
  48.     | directory |
  49.     directory _ Filename named: dirName.
  50.     directory exists
  51.         ifTrue: [directory _ FileDirectory named: directory asString]
  52.         ifFalse: 
  53.             [self error: 'Forms directory ' , dirName , ' does not exist'.
  54.             ^nil].
  55.     directory keysDo: [:each | (iconName match: each)
  56.             ifTrue: [^Form readFrom: dirName , (String with: Filename separator) , iconName]].
  57.     self error: 'Cannot find icon ' , iconName , ' in directory ' , dirName.
  58.     ^nil!
  59.  
  60. getCursor: iconName fromDirectory: dirName 
  61.     "retrieve an icon from disk"
  62.  
  63.     | directory |
  64.     directory _ Filename named: dirName.
  65.     directory exists
  66.         ifTrue: [directory _ FileDirectory named: directory asString]
  67.         ifFalse: 
  68.             [self error: 'Forms directory ' , dirName , ' does not exist'.
  69.             ^nil].
  70.     directory keysDo: [:each | (iconName match: each)
  71.             ifTrue: [^self formToCursor: (Form readFrom: dirName , (String with: Filename separator) , iconName)]].
  72.     self error: 'Cannot find cursor ' , iconName , ' in directory ' , dirName.
  73.     ^nil! !
  74.  
  75. !IconManager methodsFor: 'initialize/release'!
  76.  
  77. initDict: aDirName
  78.     " set up the dictionary of icons, ignore *.bak files "
  79.  
  80.     directory _ FileDirectory named: aDirName. 
  81.     (Filename named: aDirName) exists 
  82.         ifFalse: [PopUpNotifier message:  'Error: directory does not exist'.
  83.                   ^nil].
  84.     iconDict _ Dictionary new.
  85.     directory keysDo: 
  86.         [:each | ('*.bak' match: each)
  87.                     ifFalse: [(iconDict at: each ifAbsent: [nil]) isNil
  88.                                 ifTrue: [iconDict at: each put: nil]]]! !
  89.  
  90. !IconManager methodsFor: 'menu'!
  91.  
  92. addIcon
  93.     " add a new icon to the current directory"
  94.  
  95.     | newIcon iconName fullName|
  96.     iconName_FillInTheBlank request: 'New Icon Name' initialAnswer: ('').
  97.     iconName='' ifTrue: [^self].
  98.     iconDict isNil ifTrue: [iconDict_Dictionary new].
  99.     fullName_self dirFullName,iconName.
  100.     (Filename named: fullName) exists
  101.         ifFalse:[newIcon_Form extent: self newIconExtent.
  102.                 newIcon writeOn: fullName]
  103.         ifTrue:[PopUpNotifier message: 'An icon with this name already exists in this directory'.
  104.                 ^nil].
  105.     iconDict at: iconName put: newIcon.
  106.     currentIcon_iconName.
  107.     self changed: #icon!
  108.  
  109. changeDir
  110.  
  111.     | newDir |
  112.     newDir _ FillInTheBlank request: 'New Directory:' initialAnswer: (self dirFullName).
  113.     newDir = '' ifTrue: [^nil].
  114.     (Filename named: newDir) exists 
  115.         ifFalse: [PopUpNotifier message:  'directory ',newDir,' does not exist'.
  116.                   ^nil].
  117.     iconDict _ Dictionary new.
  118.     self initDict: newDir.
  119.     self changed: #icon!
  120.  
  121. copyIcon
  122.     " copy the current icon to another directory "
  123.  
  124.     | copyDir fullName | 
  125.     copyDir _ FillInTheBlank request: 'Directory to Copy Icon to:' initialAnswer: (self dirFullName).
  126.     copyDir = '' ifTrue: [^self]. 
  127.     (Filename named: copyDir) exists 
  128.         ifFalse: [PopUpNotifier message:  'directory ',copyDir,' does not exist'.
  129.                   ^nil].
  130.     copyDir _ copyDir,(String with: Filename separator),currentIcon.
  131.     iconDict isNil ifTrue: [iconDict _ Dictionary new].
  132.     fullName _ self pathToCurrent.
  133.     FileDirectory copyFileNamed: fullName to: copyDir!
  134.  
  135. removeIcon
  136.     " delete the icon from the current directory"
  137.  
  138.     | file | 
  139.     file _ Filename named: self pathToCurrent.
  140.     (file exists and: [(BinaryChoice message: 'Are you sure that you want to delete ',currentIcon,'?')])
  141.         ifTrue:[file delete.
  142.                 iconDict removeKey: currentIcon.
  143.                 currentIcon_nil.
  144.                 self changed: #icon]!
  145.  
  146. renameIcon
  147.     "rename the current icon in the directory"
  148.     
  149.     | newName fullName file |
  150.     newName_FillInTheBlank request: 'New Icon Name' initialAnswer: (currentIcon).
  151.     newName='' ifTrue: [^self].
  152.     fullName_ self dirFullName,newName.
  153.     (Filename named: fullName) exists
  154.         ifTrue:[PopUpNotifier message: 'An icon with this name already exists in this directory'.
  155.                 ^nil].
  156.     (iconDict at:currentIcon) writeOn: fullName.
  157.     iconDict at: newName put: (iconDict at: currentIcon).
  158.     iconDict removeKey: currentIcon.
  159.     file _ Filename named: self pathToCurrent.
  160.     file exists ifTrue:[file delete].
  161.     currentIcon_newName.
  162.     self changed: #icon!
  163.  
  164. updateList
  165.     " update the listing of the directory"
  166.  
  167.     self initDict: self dirFullName.
  168.     self changed: #icon! !
  169.  
  170. !IconEditorView methodsFor: 'displaying'!
  171.  
  172. display
  173.     self isUnlocked ifTrue: [self scrollOffset:0@0].
  174.     self displayBorder.
  175.     self displayView! !
  176.  
  177. !IconEditorController methodsFor: 'private'!
  178.  
  179. scrollDelayLength
  180.     "This method is for Textronix compatibility"
  181.  
  182.     ^5! !